package com.ty.entity;

/**
 * 用户实体类
 */
public class User {
    private Integer id;        // 用户ID
    private String username;   // 用户名
    private String account;    // 账号
    private String password;   // 密码
    private Integer permission; // 权限 1-管理员 0-普通用户

    // 构造方法
    public User() {
    }

    public User(String username, String account, String password, Integer permission) {
        this.username = username;
        this.account = account;
        this.password = password;
        this.permission = permission;
    }

    // getter和setter方法
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getPermission() {
        return permission;
    }

    public void setPermission(Integer permission) {
        this.permission = permission;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", account='" + account + '\'' +
                ", password='" + password + '\'' +
                ", permission=" + permission +
                '}';
    }

    public boolean isAdmin() {
        return this.permission == 1;
    }

    public boolean hasPermission(int requiredLevel) {
        return this.permission >= requiredLevel;
    }
}